<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class LibTime {
	var $timezone = 0;
	var $timestamp = 0;
	
	//constructor
	function LibTime() {
		$this->timestamp = time();
	}
	
	//
	function stime() {
		return date('Z') / 3600;
	}
	
	//gm
	function gm_time() {
		return ($this->time - date('Z'));
	}
	
	function gm_strtotime($time) {
		$time = strtotime($time);
		if( $time > 0 ) {
			$time -= date('Z');
		}
		
		return $time;
	}
	
	//local
	function local_maketime($hour = 0, $minute = 0, $second = 0, $month = 0, $day = 0, $year = 0) {
		$time = mktime($hour, $minute, $second, $month, $day, $year) - $this->timezone * 3600;
		
		return $time;
	}
	
	function local_gettime($timestamp = 0) {
		$time = $this->local_getdate($timestamp);
		
		return $time['0'];
	}
	
	function local_date($format, $timestamp = 0) {
		if( $timestamp === 0 ) {
			$timestamp = $this->timestamp;
		}
		
		return date($format, $timestamp);
	}
	
	function local_getdate($timestamp = 0) {
		if( $timestamp === 0 ) {
			$timestamp = $this->timestamp;
		}
		
		$timestamp = $timestamp - date('Z') + $this->timezone * 3600;
		
		return getdate($timestamp);
	}
	
	function local_gettimestamp($timestamp = 0) {
		if( $timestamp === 0 ) {
			$timestamp = $this->timestamp;
		}
		
		$timestamp = $timestamp - date('Z') + $this->timezone * 3600;
		
		return $timestamp;
	}
	
	function local_strtotime($timestamp) {
		$timestamp = strtotime($timestamp);
		if( $timestamp > 0 ) {
			$timestamp -= $this->timezone * 3600;
		}
		
		return $timestamp;
	}
}
//
?>